package tech.threekilogram.activitytasktest;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

/**
 * @author Liujin 2018-09-26:14:26
 */
public class Util {

      public static void print ( Activity activity ) {

            String taskAffinity = null;
            try {
                  ActivityInfo activityInfo = activity.getPackageManager().getActivityInfo(
                      activity.getComponentName(),
                      PackageManager.GET_META_DATA
                  );
                  taskAffinity = activityInfo.taskAffinity;
            } catch(NameNotFoundException e) {
                  e.printStackTrace();
            }
            Log.e(
                "LaunchMode: ",
                activity.getClass().getSimpleName() +
                    " taskId: " + activity.getTaskId() +
                    " affinity: " + taskAffinity +
                    " hash: " + activity.hashCode()
            );
      }

      public static String getTask ( Activity activity ) {

            String taskAffinity = null;
            try {
                  ActivityInfo activityInfo = activity.getPackageManager().getActivityInfo(
                      activity.getComponentName(),
                      PackageManager.GET_META_DATA
                  );
                  taskAffinity = activityInfo.taskAffinity;
            } catch(NameNotFoundException e) {
                  e.printStackTrace();
            }

            return activity.getClass().getSimpleName() +
                " taskId: " + activity.getTaskId() +
                " affinity: " + taskAffinity +
                " hash: " + activity.hashCode();
      }
}
